from typing import TypeVar

from zkl_aiutils_datasets.basics import Dataset, DatasetIterator, DatasetWriter, SkipExhausted

AnySample = TypeVar('AnySample')


class EmptyDatasetWriter(DatasetWriter[AnySample]):
    def write(self, sample: AnySample):
        raise StopIteration

    def flush(self):
        pass

    def close(self):
        pass


class EmptyDatasetIterator(DatasetIterator[AnySample]):
    def __next__(self) -> AnySample:
        raise StopIteration

    def __skip__(self, samples_n: int):
        if samples_n == 0:
            return
        raise SkipExhausted(0)

    def __pause__(self) -> None:
        return None


class EmptyDataset(Dataset[AnySample]):
    def __len__(self) -> int:
        return 0

    def __getitem__(self, index: int, /) -> AnySample:
        return IndexError

    def __iter__(self) -> EmptyDatasetIterator[AnySample]:
        return EmptyDatasetIterator()

    def __resume__(self, state: None = None, /) -> EmptyDatasetIterator[AnySample]:
        return EmptyDatasetIterator()
